package com.kedacom.freedomLabel.model.bean;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.kedacom.freedomLabel.excel.IRowRecord;
import com.kedacom.freedomLabel.model.db.Converters;
import com.kedacom.freedomLabel.utils.Cn2Spell;

/**
 * Author：李程
 * CreateTime：2020/2/26 22:41
 * E-mail：licheng@kedacom.com
 * Describe：
 */
@Entity
public class Product extends IFirstLetter implements IMainSelectItem, IRowRecord {

    // 索引 数据导出时 应忽略
    @NonNull
    @PrimaryKey
    public String uuid = Converters.randomUUID();

    // 产品名称
    public String name;

    // 缩写（拼音首字母）
    public String shortHand;

    // 产品编号
    public String number;

    // 是否预设组别
    public boolean openGroupSetting;

    // 预设组别 UUID
    public String groupUUID;
    public String groupName;
    public String groupNumber;

    // 单重 用于采重功能计算
    public Double singleWeight;

    // 预设扣重
    public Double preTare;

    // 标准件上限
    public Double topLimit;

    // 标准件下限
    public Double lowLimit;

    // 预设打印标签类型
    public String label;

    // 是否预设ID信息
    public Boolean openPreIDSetting;

    // 预设ID信息（存储数据格式要求：NULL-ID2-NULL-ID4-NULL-ID6）
    public String preIDInformation;

    // 创建时间
    public Long createTime;

    // 更新时间
    public Long updateTime;

    @Override
    public String getFirstLetter() {
        if (TextUtils.isEmpty(this.name)) {
            return "#";
        }
        String firstLetter = Cn2Spell.getPinYin(this.name).substring(0, 1).toUpperCase();
        if (!firstLetter.matches("[A-Z]")) {
            return "#";
        }
        return firstLetter;
    }

    @Override
    public String getItemName() {
        return this.name;
    }

    @Override
    public void setSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (obj instanceof Item) {
            Item other = (Item) obj;
            return TextUtils.equals(this.uuid, other.uuid);
        }
        return false;
    }

    @Override
    public String[] getSelectResultData() {
        return new String[]{this.uuid, this.name};
    }

    @NonNull
    @Override
    public String[] rowValues() {
        return new String[]{number, name, String.valueOf(openGroupSetting), groupNumber, groupName, String.valueOf(singleWeight), String.valueOf(preTare), String.valueOf(topLimit), String.valueOf(lowLimit)};
    }

    @Override
    public boolean[] isNumber() {
        return new boolean[0];
    }
}